#!/usr/local/bin/perl
package EX;
use strict;use warnings;
use feature qw/say/;

use Cwd qw/getcwd/;

use imv_ft;

sub extract
{
#    my ($ft,$fn,$odir,undef,$pass) = @_;
    my $com=&FT::get_com($_[0],"%f"=>$_[1],"%d"=>$_[2],"%p"=>$_[4]);
    unless($com){
	say "#ERR:INTERNAL ERROR for FT=$_[0], FN=$_[1], ODIR=$_[2], PASS=$_[4]";
	exit 1;
    }
    my $here;
    if($_[0]==$FT::FT_GZIP){
	$here=getcwd;
	chdir $_[2];
    }

    my $rc=system($com);

    chdir($here) if defined $here;
    (my $r=$_[1])=~s/\/[^\/]*$//;
    (my $s=$_[2])=~s/\/[^\/]*$//;
    if($r=~/^$s/&&$rc==0){ # archives in archive
	unlink $_[1];
	say "#MSG: $_[1] removed after extrction";
    }
    say "#ERR:command failed: $com" if $rc!=0;
    return $rc;
}

1;
